<template>
  <div class="login">
    <div class="container-login100">
      <div class="wrap-login100">
        <div class="login100-pic js-tilt" data-tilt>
          <img src="../../assets/img/login/img-01.png" alt="IMG">
        </div>

        <form class="login100-form validate-form">
				<span class="login100-form-title">
          企业在线学习平台
				</span>

          <div class="wrap-input100 validate-input">
            <input class="input100" type="text" name="email" placeholder="账号" v-model="loginform.username">
            <span class="focus-input100"></span>
            <span class="symbol-input100">
						<i class="fa fa-envelope" aria-hidden="true"></i>
					</span>
          </div>

          <div class="wrap-input100 validate-input">
            <input class="input100" type="password" name="pass" placeholder="密码" v-model="loginform.password">
            <span class="focus-input100"></span>
            <span class="symbol-input100">
						<i class="fa fa-lock" aria-hidden="true"></i>
					</span>
          </div>

          <div>
            <button class="login100-form-btn" type="button" @click="login">
              登陆
            </button>
          </div>

          <div class="text-center p-t-12">
            <a class="txt2" @click="$router.push('/resetPwd')" >
              忘记密码？
            </a>
          </div>

          <div class="text-center p-t-136">
            <a class="txt2" @click="$router.push('/regdit')">
              还没有账号？立即注册
              <i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
            </a>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      loginform: {
        username: '',
        password: '',
      },
      responseResult: []
    }
  },
  methods: {
    login() {
      this.$axios.post(
          '/login',
          {
            username: this.loginform.username,
            password: this.loginform.password
          }
      ).then(resp => {
        console.log(resp)
        if(resp.data.code===200){
            this.Cookies.set('userName',resp.data.user.name);
            this.Cookies.set('userId',resp.data.user.id);
            this.Cookies.set('userImgUrl',resp.data.user.imgUrl);
            this.Cookies.set('userType',resp.data.user.type);
            if(resp.data.user.petName!==null&&resp.data.user.petName!=='')
              this.Cookies.set('userName',resp.data.user.petName);
            this.$message({
            type: 'success',
            message:'登陆成功',
            });
          this.$router.push({path:'/home'})
        }
        else {
          this.$message({
            type: 'error',
            message:'登陆失败',
          });
        }
      })
    }
  }
}

</script>

<style scoped>
@import "../../assets/css/font.css";
@import "../../assets/css/main.css";
@import "../../assets/css/util.css";
</style>
